function Res  = adjFFUsing4LoopsAndH(Im)
imageSize=size(Im);
% validity test of the input
if (length(imageSize)~=2) %not a 2D image
   error('Input must be a 2D image');
end

if (imageSize(1)~=imageSize(2))
   error('Input image must be square');
end

if (mod(imageSize(1),2)~=0)
   error('Input image must have even side');
end

% initialize constants and data structures
n=imageSize(1);
Res=zeros(n);
H=calculateH(n);
for u=-n/2:n/2-1
    for v=-n/2:n/2-1
        for s=-n/2:n/2-1
            for t=-n/2:n/2-1
                Res(u+n/2+1,v+n/2+1)=Res(u+n/2+1,v+n/2+1)+...
                    Im(s+n/2+1,t+n/2+1)*H(u-s+n,v-t+n);
            end
        end
    end
end